home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Animation Wizard.dir / 00013_ScoreMgr.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  11.5 KB  |  371 lines

  1. property iUsersScoreSelection, iGeneratedScoreSelection, ichStart, ichEnd, iFrameStart, iFrameEnd, iStageWidth, iStageHeight, iStageRight, iStageBottom, iChannelAvailList, ichReselect, iLocReselect, ikChStart, ikChEnd, ikFrameStart, ikFrameEnd, iLastFrame, iNeedClean
  2.  
  3. on birth me
  4.   tell the stage
  5.     set iStageRight to the stageRight
  6.     set iStageBottom to the stageBottom
  7.     set iStageWidth to iStageRight - the stageLeft
  8.     set iStageHeight to iStageBottom - the stageTop
  9.   end tell
  10.   set ikChStart to 1
  11.   set ikChEnd to 2
  12.   set ikFrameStart to 3
  13.   set ikFrameEnd to 4
  14.   set iChannelAvailList to []
  15.   set iGeneratedScoreSelection to []
  16.   set ichReselect to 18
  17.   return me
  18. end
  19.  
  20. on mGetStageWidth me
  21.   return iStageWidth
  22. end
  23.  
  24. on mGetStageHeight me
  25.   return iStageHeight
  26. end
  27.  
  28. on mGetStageRight me
  29.   return iStageRight
  30. end
  31.  
  32. on mGetStageBottom me
  33.   return iStageBottom
  34. end
  35.  
  36. on mInit me, nFramesNeeded, nChannelsNeeded
  37.   global gDevelopmentFlag
  38.   if nFramesNeeded > 32000 then
  39.     alert("The combination of text and settings you have chosen would generate an " & "animation of more than 32000 frames.  Please simplify your selections and try again.")
  40.     return 0
  41.   end if
  42.   tell the stage
  43.     set iUsersScoreSelection to the scoreSelection
  44.     set iLastFrame to the lastFrame
  45.     set iStageRight to the stageRight
  46.     set iStageBottom to the stageBottom
  47.     set iStageWidth to iStageRight - the stageLeft
  48.     set iStageHeight to iStageBottom - the stageTop
  49.   end tell
  50.   if iUsersScoreSelection = [] then
  51.     alert("Please select a range of cells or frames in the score and try again.")
  52.     return 0
  53.   end if
  54.   if gDevelopmentFlag then
  55.     mForceSelection(me)
  56.   end if
  57.   set iLocReselect to the loc of sprite ichReselect
  58.   puppetSprite(ichReselect, 1)
  59.   set firstScoreSelectionList to getAt(iUsersScoreSelection, 1)
  60.   set ichStart to getAt(firstScoreSelectionList, ikChStart)
  61.   set ichEnd to getAt(firstScoreSelectionList, ikChEnd)
  62.   set iFrameStart to getAt(firstScoreSelectionList, ikFrameStart)
  63.   set iFrameEnd to getAt(firstScoreSelectionList, ikFrameEnd)
  64.   set theGeneratedFrameEnd to iFrameStart + nFramesNeeded - 1
  65.   set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  66.   if theEnd >= iLastFrame then
  67.     set iNeedClean to 1
  68.     tell the stage
  69.       beginRecording()
  70.       go(theEnd + 5)
  71.       set the frameTempo to 5
  72.       endRecording()
  73.     end tell
  74.   else
  75.     set iNeedClean to 0
  76.   end if
  77.   set iChannelAvailList to []
  78.   if (ichStart = -5) and (ichEnd = 48) then
  79.     repeat with ch = 1 to 48
  80.       add(iChannelAvailList, ch)
  81.     end repeat
  82.     tell the stage
  83.       beginRecording()
  84.       if iFrameEnd >= iFrameStart then
  85.         go(iFrameStart)
  86.         repeat with theFrameNum = iFrameStart to iFrameEnd
  87.           set the frameLabel to 0
  88.           deleteFrame()
  89.         end repeat
  90.       end if
  91.       tell the stage
  92.         if iFrameStart = 1 then
  93.           go(1)
  94.         else
  95.           go(iFrameStart - 1)
  96.         end if
  97.         repeat with i = 1 to nFramesNeeded
  98.           insertFrame()
  99.         end repeat
  100.         if iFrameStart = 1 then
  101.           go(1)
  102.         else
  103.           go(iFrameStart - 1)
  104.         end if
  105.       end tell
  106.       set theEnd to max(theGeneratedFrameEnd, iFrameEnd)
  107.       if theEnd >= iLastFrame then
  108.         set iNeedClean to 1
  109.         go(theEnd + 5)
  110.         set the frameTempo to 5
  111.       else
  112.         set iNeedClean to 0
  113.       end if
  114.       endRecording()
  115.     end tell
  116.     set iGeneratedScoreSelection to [[-5, 48, iFrameStart, theGeneratedFrameEnd]]
  117.   else
  118.     set iGeneratedScoreSelection to []
  119.     set nItems to count(iUsersScoreSelection)
  120.     repeat with thisSelection = 1 to nItems
  121.       set thisScoreSelectionList to getAt(iUsersScoreSelection, thisSelection)
  122.       set thisChStart to getAt(thisScoreSelectionList, ikChStart)
  123.       if thisChStart <= 0 then
  124.         alert("Please make your score selection in channels 1 through 48")
  125.         mClean(me)
  126.         return 0
  127.       end if
  128.       set thisChEnd to getAt(thisScoreSelectionList, ikChEnd)
  129.       set thisScoreSelection to [thisChStart, thisChEnd, iFrameStart, theGeneratedFrameEnd]
  130.       addAt(iGeneratedScoreSelection, thisScoreSelection)
  131.       repeat with thisCh = thisChStart to thisChEnd
  132.         add(iChannelAvailList, thisCh)
  133.       end repeat
  134.     end repeat
  135.     set nChannelsAvail to count(iChannelAvailList)
  136.     if nChannelsNeeded > nChannelsAvail then
  137.       alert("Your animation requires" && nChannelsNeeded && "channels, " & "but you have only selected" && nChannelsAvail && "channels.  " & "Please select more and try again.")
  138.       mClean(me)
  139.       return 0
  140.     end if
  141.     set nFramesSelected to iFrameEnd - iFrameStart + 1
  142.     if nFramesSelected < nFramesNeeded then
  143.       set nFramesToAdd to nFramesNeeded - nFramesSelected
  144.       tell the stage
  145.         go(iFrameEnd)
  146.         beginRecording()
  147.         repeat with i = 1 to nFramesToAdd
  148.           duplicateFrame()
  149.           set the frameTempo to 0
  150.         end repeat
  151.         endRecording()
  152.         go(iFrameStart)
  153.       end tell
  154.     end if
  155.   end if
  156.   tell the stage
  157.     beginRecording()
  158.     go(iFrameStart)
  159.     repeat with thisFrame = iFrameStart to iFrameEnd
  160.       repeat with chIndex = 1 to nChannelsAvail
  161.         set thisCh to getAt(iChannelAvailList, chIndex)
  162.         if the castNum of sprite thisCh <> 0 then
  163.           set the type of sprite thisCh to 0
  164.         end if
  165.       end repeat
  166.       set the frameTempo to 0
  167.       updateFrame()
  168.     end repeat
  169.     endRecording()
  170.   end tell
  171.   updateStage()
  172.   return 1
  173. end
  174.  
  175. on mShowReselect me
  176.   set the scoreSelection to iUsersScoreSelection
  177.   set the loc of sprite ichReselect to iLocReselect
  178.   set the castNum of sprite ichReselect to the number of member "ReselectButton"
  179.   updateStage()
  180. end
  181.  
  182. on mForceSelection me
  183.   set nItems to count(iUsersScoreSelection)
  184.   repeat with thisSelectionNum = 1 to nItems
  185.     set thisScoreSelectionList to getAt(iUsersScoreSelection, thisSelectionNum)
  186.     set thisStart to getAt(thisScoreSelectionList, ikFrameStart)
  187.     set thisEnd to getAt(thisScoreSelectionList, ikFrameEnd)
  188.     if (thisStart < 101) or (thisEnd < 101) then
  189.       setAt(thisScoreSelectionList, ikFrameStart, 101)
  190.       setAt(thisScoreSelectionList, ikFrameEnd, 125)
  191.       setAt(iUsersScoreSelection, thisSelectionNum, thisScoreSelectionList)
  192.     end if
  193.   end repeat
  194. end
  195.  
  196. on mReselect me
  197.   if iGeneratedScoreSelection = [] then
  198.     alert("Internal error, mReselect - there is nothing to reselect.")
  199.     return 
  200.   end if
  201.   tell the stage
  202.     set the scoreSelection to iGeneratedScoreSelection
  203.   end tell
  204. end
  205.  
  206. on mGetGeneratedScoreSelection me
  207.   return iGeneratedScoreSelection
  208. end
  209.  
  210. on mGetStartFrame me
  211.   return iFrameStart
  212. end
  213.  
  214. on mGetNextSelectedChannel me
  215.   if iChannelAvailList = [] then
  216.     alert("Internal error, mGetNextSelectedChannel is out of available channels")
  217.     return -99
  218.   end if
  219.   set theCh to getAt(iChannelAvailList, 1)
  220.   deleteAt(iChannelAvailList, 1)
  221.   return theCh
  222. end
  223.  
  224. on mWriteSprite me, f, ch, cm, theForeColor, theBackColor, x, y, w, h
  225.   global gkTransparentInk
  226.   tell the stage
  227.     go(f)
  228.     beginRecording()
  229.     set the castNum of sprite ch to cm
  230.     set the foreColor of sprite ch to theForeColor
  231.     set the backColor of sprite ch to theBackColor
  232.     set the locH of sprite ch to x
  233.     set the locV of sprite ch to y
  234.     set the ink of sprite ch to gkTransparentInk
  235.     set the tweened of sprite(ch) to 1
  236.     if w <> 0 then
  237.       set the width of sprite ch to w
  238.     end if
  239.     if h <> 0 then
  240.       set the height of sprite ch to h
  241.     end if
  242.     updateFrame()
  243.     endRecording()
  244.   end tell
  245. end
  246.  
  247. on mWriteFrameControl me, theFrame, theControl, theValue
  248.   if theControl = #transition then
  249.     copyToClipBoard(member the number of member theValue)
  250.     set castNumTransTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  251.   end if
  252.   tell the stage
  253.     go(theFrame)
  254.     beginRecording()
  255.     case theControl of
  256.       #label:
  257.         set the frameLabel to theValue
  258.       #tempo:
  259.         set the frameTempo to theValue
  260.       #transition:
  261.         pasteClipBoardInto(member castNumTransTarget)
  262.         set the name of member castNumTransTarget to "Transition" && string(the ticks)
  263.         set the frameTransition to castNumTransTarget
  264.       #Sound1:
  265.         set the frameSound1 to theValue
  266.       #Sound2:
  267.         set the frameSound2 to theValue
  268.       otherwise:
  269.         alert("Bad control value passed to mWriteFrameControl" & theControl)
  270.     end case
  271.     updateFrame()
  272.     endRecording()
  273.   end tell
  274. end
  275.  
  276. on mWriteFrameLabel me, theFrame, theLabel
  277.   mWriteFrameControl(me, theFrame, #label, theLabel)
  278. end
  279.  
  280. on mWriteFrameDelay me, theFrame, nSeconds
  281.   mWriteFrameControl(me, theFrame, #tempo, -nSeconds)
  282. end
  283.  
  284. on mWriteFrameTempo me, theFrame, theTempo
  285.   mWriteFrameControl(me, theFrame, #tempo, theTempo)
  286. end
  287.  
  288. on mWriteFrameTransition me, theFrame, theTransition
  289.   mWriteFrameControl(me, theFrame, #transition, theTransition)
  290. end
  291.  
  292. on mWriteFrameSound1 me, theFrame, theSound1
  293.   mWriteFrameControl(me, theFrame, #Sound1, theSound1)
  294. end
  295.  
  296. on mWriteFrameSound2 me, theFrame, theSound2
  297.   mWriteFrameControl(me, theFrame, #Sound2, theSound2)
  298. end
  299.  
  300. on mWriteFrame me, frameList
  301.   global gkTransparentInk
  302.   tell the stage
  303.     beginRecording()
  304.     repeat with theFrameNum = 1 to count(frameList)
  305.       set theFrameStuff to getAt(frameList, theFrameNum)
  306.       go(getAt(theFrameStuff, 1))
  307.       repeat with theChannel = 2 to count(theFrameStuff)
  308.         set theChannelList to getAt(theFrameStuff, theChannel)
  309.         set theChannelType to getAt(theChannelList, 1)
  310.         case theChannelType of
  311.           #label:
  312.             set the frameLabel to getAt(theChannelList, 2)
  313.           #tempo:
  314.             set the frameTempo to getAt(theChannelList, 2)
  315.           #palette:
  316.             set the framePalette to getAt(theChannelList, 2)
  317.           #transition:
  318.             set theTransition to getAt(theChannelList, 2)
  319.             set transitionMember to new(#transition)
  320.             if theTransition = "wipe down" then
  321.               set the transitionType of transitionMember to 3
  322.               set the chunkSize of transitionMember to 2
  323.             else
  324.               if theTransition = "dissolve, pixels fast" then
  325.                 set the transitionType of transitionMember to 23
  326.                 set the chunkSize of transitionMember to 1
  327.               end if
  328.             end if
  329.             set the duration of transitionMember to 2000
  330.             set the frameTransition to transitionMember
  331.           #Sound1:
  332.             set the frameSound1 to getAt(theChannelList, 2)
  333.           #Sound2:
  334.             set the frameSound2 to getAt(theChannelList, 2)
  335.           #sprite:
  336.             set theSpriteNum to getAt(theChannelList, 2)
  337.             set the castNum of sprite theSpriteNum to getAt(theChannelList, 3)
  338.             set the foreColor of sprite theSpriteNum to getAt(theChannelList, 4)
  339.             set the backColor of sprite theSpriteNum to getAt(theChannelList, 5)
  340.             set the locH of sprite theSpriteNum to getAt(theChannelList, 6)
  341.             set the locV of sprite theSpriteNum to getAt(theChannelList, 7)
  342.             set the ink of sprite theSpriteNum to gkTransparentInk
  343.             set the tweened of sprite(theSpriteNum) to 1
  344.             set w to getAt(theChannelList, 8)
  345.             set h to getAt(theChannelList, 9)
  346.             if w <> 0 then
  347.               set the width of sprite theSpriteNum to w
  348.             end if
  349.             if h <> 0 then
  350.               set the height of sprite theSpriteNum to h
  351.             end if
  352.         end case
  353.       end repeat
  354.       updateFrame()
  355.     end repeat
  356.     endRecording()
  357.   end tell
  358. end
  359.  
  360. on mClean me
  361.   if iNeedClean = 1 then
  362.     tell the stage
  363.       set iLastFrame to the lastFrame
  364.       beginRecording()
  365.       go(iLastFrame)
  366.       set the frameTempo to 0
  367.       endRecording()
  368.     end tell
  369.   end if
  370. end
  371.